app.controller('exportLoanExcelCtrl', function($element, $scope, $state, rest, user, uploadConf, tipService, $window, $rootScope, decoJavaUrlLsf) {
    $scope.idstring = angular.copy($scope.ngDialogData, {});
    var token = $window.localStorage.getItem("token");

    rest.decoJava({
        type: "post",
        url: "/tenancy-sys/admin/decorateOrderInfo/getOrderExcelFileds",
        data: "",
        beforeSend: function(request) {
            request.setRequestHeader("token", token);
        },
        success: function(res) {
            $scope.ExcelDatas = res;
            $scope.$apply();
            $("#_ajaxForm").attr("action", decoJavaUrlLsf + "/tenancy-sys/admin/decorateOrderInfo/exportDecrateOrderExcel"); //form请求地址
        }
    })

    $scope.keysstring = "";
    $scope.valuestring = "";
    $(document).on("click", ".checkboxBar span input[type='checkbox']", function() {
        var _id = "";
        var _value = "";
        $(".checkboxBar input[type='checkbox']").each(function() {
            if ($(this).is(":checked")) {
                _id += $(this).attr("data-id") + ",";
                _value += $(this).attr("data-valueString") + ",";
            }
        })
        _id = _id.substring(0, _id.length - 1)
        _value = _value.substring(0, _value.length - 1)
        $scope.keysstring = _id;
        $scope.valuestring = _value;
        $scope.$apply();
        console.log($scope.keysstring)
        console.log($scope.valuestring)
        /*var index = $(this).attr("data-index");
        if ($(this).is(":checked")) {
            $(".checkboxBar2 span input[data-index='" + index + "']").prop("checked", true);
        } else {
            $(".checkboxBar2 span input[data-index='" + index + "']").prop("checked", false);
        }

        //数据处理1
        var keysArr = [];
        angular.element(".checkboxBar span input[type='checkbox']").each(function() {
            if ($(this).is(":checked")) {
                keysArr.push($(this).val());
            }
        });
        var _keysstring = "";
        angular.forEach(keysArr, function(data) {
            _keysstring += data + ',';
        })
        var _keysstring = _keysstring.substring(0, _keysstring.length - 1);
        //数据处理2
        var colArr = [];
        angular.element(".checkboxBar2 span input[type='checkbox']").each(function() {
            if ($(this).is(":checked")) {
                colArr.push($(this).val());
            }
        });
        var colstring = "";
        angular.forEach(colArr, function(data) {
            colstring += data + ',';
        })
        var colstring = colstring.substring(0, colstring.length - 1);
        $scope.keysstring = _keysstring
        $scope.colstring = colstring
        $scope.$apply();*/

    });

    //全部选中和取消
    $scope.allMenus = function(e){
        var This = angular.element(e.target);
        if(This.is(":checked")){
            angular.element(".checkchilds").prop("checked",true);
        } else{
            angular.element(".checkchilds").prop("checked",false);
        }
        
        //数据处理1
        var keysArr = [];
        var valuesArr = [];
        angular.element(".checkboxBar input[type='checkbox']").each(function() {
            if ($(this).is(":checked")) {
                keysArr.push($(this).attr('data-id'));
                valuesArr.push($(this).attr('data-valueString'));
            }
        });
        var _keysstring = "";
        var _valuestring = "";
        angular.forEach(keysArr, function(data) {
            _keysstring += data + ',';
        })
        angular.forEach(valuesArr, function(data) {
            _valuestring += data + ',';
        })
        var _keysstring = _keysstring.substring(0, _keysstring.length - 1);
        var _valuestring = _valuestring.substring(0, _valuestring.length - 1);
        
        $scope.keysstring = _keysstring;
        $scope.valuestring = _valuestring;
        //$scope.$apply();
    }

    $scope.exportData = function() {

        if ($scope.keysstring == "") {
            layer.msg("没有选中项", {
                offset: 't',
                icon: 2
            });
        } else {
            $("#_ajaxForm").submit();
            $scope.closeThisDialog();
        }
    }

    $scope.hideBtn = function() {
        $scope.closeThisDialog();
    }

});